package com.lanbu.web.controller.camera;


import com.lanbu.common.annotation.Log;
import com.lanbu.common.core.controller.BaseController;
import com.lanbu.common.core.domain.AjaxResult;
import com.lanbu.common.core.page.TableDataInfo;
import com.lanbu.common.enums.BusinessType;
import com.lanbu.common.utils.poi.ExcelUtil;
import com.lanbu.system.domain.camera.CaCamera;
import com.lanbu.system.service.ICaCameraService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 摄像头Controller
 *
 * @author lanbu
 * @date 2024-03-12
 */
@Api(tags = "摄像头")
@RestController
@RequestMapping("/camera/camera")
public class CaCameraController extends BaseController {
    @Autowired
    private ICaCameraService caCameraService;

    /**
     * 查询摄像头列表
     */
    @ApiOperation(value = "查询摄像头列表")
    @PreAuthorize("@ss.hasPermi('camera:camera:query')")
    @GetMapping("/list")
    public TableDataInfo list(CaCamera caCamera) {
        startPage();
        List<CaCamera> list = caCameraService.selectCaCameraList(caCamera);
        return getDataTable(list);
    }

    /**
     * 根据小区或电梯Id查询所属的摄像头列表
     */
    @ApiOperation(value = "根据小区或电梯Id查询所属的摄像头列表")
    @PreAuthorize("@ss.hasPermi('camera:camera:query')")
    @GetMapping("/list/{id}")
    public AjaxResult list(@PathVariable String id) {
        List<CaCamera> list = caCameraService.selectCaCameraListByDeptId(id);
        return success(list);
    }

    /**
     * 获取摄像头详细信息
     */
    @ApiOperation(value = "通过id获取摄像头详细信息")
    @PreAuthorize("@ss.hasPermi('camera:camera:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(caCameraService.selectCaCameraById(id));
    }

    /**
     * 新增摄像头
     */
    @ApiOperation(value = "新增摄像头")
    @PreAuthorize("@ss.hasPermi('camera:camera:add')")
    @Log(title = "摄像头", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaCamera caCamera) {
        return toAjax(caCameraService.insertCaCamera(caCamera));
    }

    /**
     * 修改摄像头
     */
    @ApiOperation(value = "修改摄像头")
    @PreAuthorize("@ss.hasPermi('camera:camera:edit')")
    @Log(title = "摄像头", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaCamera caCamera) {
        return toAjax(caCameraService.updateCaCamera(caCamera));
    }

    /**
     * 删除摄像头
     */
    @ApiOperation(value = "删除摄像头")
    @PreAuthorize("@ss.hasPermi('camera:camera:remove')")
    @Log(title = "摄像头", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(caCameraService.deleteCaCameraByIds(ids));
    }


    /**
     * 导出摄像头列表
     */
    @ApiOperation(value = "导出摄像头列表")
    @PreAuthorize("@ss.hasPermi('camera:camera:export')")
    @Log(title = "摄像头", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaCamera caCamera) {
        List<CaCamera> list = caCameraService.selectCaCameraList(caCamera);
        ExcelUtil<CaCamera> util = new ExcelUtil<CaCamera>(CaCamera.class);
        util.exportExcel(response, list, "摄像头数据");
    }


}
